//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class DataModel: IOfficeXmlSerializable
    {
        private List<Point> _ptLst = new List<Point>();
        private List<Connection> _cxnLst = new List<Connection>();
        private BackgroundFormatting _bg;
        private OfficeArtExtensionList _extLst;
        private WholeE2oFormatting _whole;

        public void ReadXml (ReadContext context)
        {
            using (var c = context.Read("dataModel"))
            {
                _ptLst.Clear();
                _ptLst.AddRange(c.ReadElements<Point>("ptLst", Point.xmlName));
                _cxnLst.AddRange(c.ReadElements<Connection>("cxnLst", Connection.xmlName));
                _bg = c.ReadOptionalElement<BackgroundFormatting>(BackgroundFormatting.xmlName);
                _whole = c.ReadOptionalElement<WholeE2oFormatting>("whole");
                _extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }

        }
        public void WriteXml (WriteContext context)
        {
            using (var c = context.Write("dataModel"))
            {
               // if (_ptLst.Count > 0)
                {
                    using (var c2 = c.Write("ptLst"))
                    { c2.WriteElements(this._ptLst); }
                }
               // if (_cxnLst.Count > 0)
                {
                    using (var c2 = c.Write("cxnLst"))
                    { c2.WriteElements(this._cxnLst); }
                }
                c.WriteOptionalElement(_bg  );
                c.WriteOptionalElement(_whole  );
               //\\ c.WriteOptionalElement(_extLst);
            }
        }
    }
}